<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-9-24
 * Time: 下午5:30
 * @author 郑钟良<zzl@ourstu.com>
 */

namespace Usercenter\Model;


use Think\Model;

class MemberInfoModel extends Model {

    protected $tableName='member_info';

    protected $_auto=array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', '1', self::MODEL_INSERT),
    );

    protected $insertFields = 'uid,name,doing1,doing2,sex,national,site_province,site_city,site_area,sign,height,weight,bwh,birthday,home_province,home_city,home_area,company,mobile,qq,wechat,email,label'; // 新增数据的时候允许写入
    protected $updateFields = 'uid,name,doing1,doing2,sex,national,site_province,site_city,site_area,sign,height,weight,bwh,birthday,home_province,home_city,home_area,company,mobile,qq,wechat,email,label'; // 编辑数据的时候允许写入

    public function add_info($data){
        $data=$this->create($data);
        $res=$this->add($data);
        return $res;
    }

    public function update_info($data){
        $id=$data['id'];
        $data=$this->create($data);
        $res=$this->where(array('id'=>$id))->save($data);
        return $res;
    }

    public function get_info($uid){
        $uid=$uid?$uid:is_login();
        $member_info=$this->where(array('uid'=>$uid))->find();
        return $member_info;
    }

    public function edit_info($data){
        $data['uid']=$uid=is_login();
        $id=$this->where(array('uid'=>$uid))->getField('id');
        if($id){
            $data['id']=$id;
            $res=$this->update_info($data);
        }else{
            $res=$this->add_info($data);
        }
        return $res;
    }
} 